import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";
import {OffsetDateTime} from "@js-joda/core";

export interface QueryDirectSaleClientsRequest {
    name?: string
}

export function queryDirectSaleClients(queryDirectSaleClientsRequest: QueryDirectSaleClientsRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryDirectSaleClientsResponse>>("/directSaleClients", {...queryDirectSaleClientsRequest, ...pageable.toRequestParams()})
}

export interface QueryDirectSaleClientsResponse{
    id:number
    name:string
    amount:number
    lastOrderSubmittedDateTime: OffsetDateTime
}

export interface CreateDirectSaleClientRequest{
    name:string
}

export function createDirectSaleClient(createDirectSaleClientRequest:CreateDirectSaleClientRequest){
    return fetcher.post("directSaleClients",{},createDirectSaleClientRequest)
}

export function updateDirectSaleClient(id:number,createDirectSaleClientRequest:CreateDirectSaleClientRequest){
    return fetcher.put(`directSaleClients/${id}`,{},createDirectSaleClientRequest)
}

export function getAllDirectSaleClient(){
    return fetcher.get<Array<NumberIdAndName>>("directSaleClients")
}